*------------------------------------------------------------------------------**------------------------------------------------------------------------------*
* Load *
*------------------------------------------------------------------------------**------------------------------------------------------------------------------*

use "${datadir_el}\1314 BoE data", clear
append using "${datadir_el}\1415 BoE data"
append using "${datadir_el}\1516 and 1617 BoE data"
gen newdata = 0
	
append using "${datadir_el}\1516 and 1617 Q4 BoE data"	// data until 2017 Q1
duplicates drop schemeid-estimatedcompl, force
bysort schemeid (new): keep if _n == _N			// keep more recent if same schemeid (24 obs deleted)



*--- Corrections in the data
replace schemepostcode = "SO19 9SZ" if schemepostcode == "S)19 9SZ"
replace schemepostcode = "SO51 0AY" if schemepostcode == "S)51 0AY"


/* date */
gen dated = date(estimatedcompleteddate,"DMY")
format dated %td

gen datem = mofd(dated)
format datem %tm

gen datey = year(dated)


/* variable for merge */
gen pcd 	= itrim(schemepostcode)
replace pcd = regexr(pcd," ","")

gen pdistrict = regexs(0) if ///
	regexm(schemepostcode, "[A-Z]+[0-9]+[A-Z]?")


	
/* Bank ID */
gen lender_id = 204503 if lendersname == "Aldermore" 
replace lender_id = 169628 if lendersname == "Halifax" 
replace lender_id = 164992 if lendersname == "Leeds"
replace lender_id = 121878 if lendersname == "Nat West"
replace lender_id = 106078 if lendersname == "Nationwide"
replace lender_id = 494549 if lendersname == "Precise" 
replace lender_id = 106054 if lendersname == "Santander"
replace lender_id = 153706 if lendersname == "Skipton"
replace lender_id = 503963 if lendersname == "Virgin Money"
replace lender_id = 122702 if lendersname == "Woolwich"


*--- Variables
gen equity = purchaseprice - mortgage - deposit		

save "${datadir}\HCA_full", replace
